<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<style type="text/css">
	div>div{
		width: 30px;
		height: 30px;
		background-color: pink;
		display: inline-block;
		margin: 5px;
		text-align:center;   /*文本居中显示*/
	}
</style>
<script type="text/javascript">
	function myfn(){
		var i1 =document.getElementById("i1");
		var i2 =document.getElementById("i2");  //获取文本框内输入的列数
		var d =document.getElementById("d1");
		//遍历行数
		for(var j=0;j<i1.value;j++){
			
			//遍历一行的个数
			for(var i=0;i<i2.value;i++){
				d.innerHTML+="<div>a</div>";
			}
			//添加换行
			d.innerHTML+="<br>";
		}
	}
</script>
</head>
<body>
<input type="text" id="i1" placeholder="行数">
<input type="text" id="i2" placeholder="列数">
<input type="button" value="添加" onclick="myfn()">
<div id="d1"></div>
</body>
</html>